
from PyQt5.QtWidgets import QApplication,QWidget,QDesktopWidget,QMainWindow,QHBoxLayout,QVBoxLayout
from PyQt5.QtGui import QIcon, QPixmap,QPalette,QBrush
from PyQt5.QtWidgets import QPushButton,QLineEdit,QTableWidget,QTableWidgetItem,QLabel
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMessageBox,QMenu,QFileDialog,QComboBox,QTextBrowser,QSplitter,QFrame,QRadioButton
import pandas as pd
from PyQt5.QtWidgets import QComboBox, QLineEdit, QListWidget, QCheckBox, QListWidgetItem, QApplication,QProgressBar
from PyQt5.QtWidgets import QToolTip,QAction,qApp,QToolBar
from PyQt5.QtCore import pyqtSignal
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QThread,pyqtSignal,QSize

import chardet
import PyQt5.sip
import pandas as pd
import numpy as np
from scipy import stats
from pykrige.ok import OrdinaryKriging
from pykrige.uk import UniversalKriging
from scipy.optimize import curve_fit
from scipy import stats
import re
import random
# from QCandyUi.CandyWindow import colorful
# from QCandyUi import CandyWindow

class thrings(QThread):

    success = pyqtSignal(list)
    error = pyqtSignal(list)
    def __init__(self,*args,**kwargs):
        super().__init__(*args,**kwargs)
    def c(self,text):
        self.text=text



    def run(self):
        if self.text.split('.')[1] == 'txt':
            self.get_file_encoding()

        if self.text.split('.')[1] == 'txt':
            if len(str(pd.read_csv(self.text, encoding=self.encoding).iloc[0,0]).split('\t')) == 1:
                self.success.emit([pd.read_csv(self.text, encoding=self.encoding)])
            else:
                data_ = pd.read_csv(self.text, encoding=self.encoding, sep='\t')
                self.success.emit([data_])
        # if self.text.split('.')[1] == 'xls' or 'xlsx':
        elif self.text.split('.')[1] == 'csv':
            data_csv = pd.read_csv(self.text)
            self.success.emit([data_csv])
        elif self.text.split('.')[1] == 'xls' or 'xlsx':
            data = pd.read_excel(self.text)
            self.success.emit([data])
        else:
            self.error.emit(['错误'])

    def get_file_encoding(self):
        f3 = open(self.text, mode='rb')  # 以二进制模式读取文件
        data = f3.read()  # 获取文件内容
        f3.close()  # 关闭文件

        result = chardet.detect(data)  # 检测文件内容
        self.encoding=result.get("encoding")

class Suan(QThread):
    success = pyqtSignal(str)
    error = pyqtSignal(str)
    bai=pyqtSignal(int)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def c(self, label,can,save,s,z,h,data,path,highcan):
        self.label =label
        self.can=can
        self.save=save
        self.s=s
        self.z=z
        self.h=h
        self.data=data
        self.path=path
        self.highcan=highcan
    def run(self):
        try:
            self.bai.emit(0)
            date_station = self.z.copy()
            date_station.fillna(0, inplace=True)
            date_station = date_station[[self.label[1][0], self.label[1][1], self.label[1][3], self.label[1][2]]]
            date_station[self.label[1][0]].replace('[^\d.]', 0.1, regex=True, inplace=True)
            date_station[self.label[1][3]].replace('[^\d.]', 0.1, regex=True, inplace=True)
            date_station[self.label[1][2]].replace('[^\d.]', 0.1, regex=True, inplace=True)
            date_station = date_station[-date_station[self.label[1][0]].isin([0.1])]
            date_station = date_station[-date_station[self.label[1][3]].isin([0.1])]
            date_station = date_station[-date_station[self.label[1][2]].isin([0.1])]
            date_station.reset_index(drop=True)
            date_station[self.label[1][0]] = date_station[self.label[1][0]].astype(int)
            date_station[self.label[1][3]] = date_station[self.label[1][3]].astype(float)
            date_station[self.label[1][2]] = date_station[self.label[1][2]].astype(float)
            date_station[self.label[1][1]] = date_station[self.label[1][1]].astype(str)
            date_slope_point = self.h.copy()
            date_slope_point.fillna(0, inplace=True)
            date_slope_point[self.label[2][0]].replace('[^\d.]', 0.1, regex=True, inplace=True)
            date_slope_point[self.label[2][1]].replace('[^\d.]', 0.1, regex=True, inplace=True)
            date_slope_point[self.label[2][2]].replace('[^\d.]', 0.1, regex=True, inplace=True)
            date_slope_point = date_slope_point[-date_slope_point[self.label[2][0]].isin([0.1])]
            date_slope_point = date_slope_point[-date_slope_point[self.label[2][1]].isin([0.1])]
            date_slope_point = date_slope_point[-date_slope_point[self.label[2][2]].isin([0.1])]
            date_slope_point.reset_index(drop=True)
            date_slope_point[self.label[2][0]] = date_slope_point[self.label[2][0]].astype(int)
            date_slope_point[self.label[2][1]] = date_slope_point[self.label[2][1]].astype(float)
            date_slope_point[self.label[2][2]] = date_slope_point[self.label[2][2]].astype(float)
            date_slope_point[self.label[2][3]] = date_slope_point[self.label[2][3]].astype(str)
            date_slope_point = date_slope_point[date_slope_point[self.label[2][3]].str.contains('雨', na=False)]
            date_slope_point = date_slope_point[[self.label[2][1], self.label[2][2], self.label[2][0]]]
            time = self.label[2][0]
            date_slope_point.drop(date_slope_point[date_slope_point[time] < 19500000].index, inplace=True)
            date_slope_point.drop(date_slope_point[date_slope_point[time] > 21200000].index, inplace=True)
            date_slope_point.drop(date_slope_point[date_slope_point[time] % 100 == 0.0].index, inplace=True)
            date_station_date = self.s.copy()
            date_station_date.fillna(0, inplace=True)
            date_station_date[self.label[0][0]].replace('[^\d.]',0.1,regex=True, inplace=True)
            date_station_date[self.label[0][-1]].replace('[^\d.]', 0.1, regex=True, inplace=True)
            date_station_date=date_station_date[-date_station_date[self.label[0][0]].isin([0.1])]
            date_station_date = date_station_date[-date_station_date[self.label[0][-1]].isin([0.1])]
            date_station_date.reset_index(drop=True)
            date_station_date[self.label[0][0]]=date_station_date[self.label[0][0]].astype(int)
            date_station_date[self.label[0][-1]] = date_station_date[self.label[0][-1]].astype(int)
            date_slope_point.sort_values(by=[self.label[2][0]], ascending=True, inplace=True)
            date_slope_point.reset_index(drop=True)
            date_slope_point[self.label[2][0]] = date_slope_point[self.label[2][0]].astype(int)
            self.success.emit('提示:\n如果程序运行时间较长，说明找到了较多的降雨型滑坡，在降雨数据库中匹配到了较多的站点，请耐心等待')
            if date_slope_point.empty:
                self.error.emit('你的滑坡数据中有效的降雨型滑坡似乎没有，其中滑坡发生时间为八位以下的无法估计其发生时间将被剔除，请检查你的滑坡数据')
            self.bai.emit(5)

            # date_station=date_station[-date_station.name.isin(['南昌县','临川'])]
            def data_select(date_station, date_station_date, date_slope_point, day):
                station_hai_sum=[]
                station_rain_sum=[]
                station_data_sum=[]
                for i in list(date_station[self.label[1][0]].values):
                    station_data = date_station_date[date_station_date[self.label[0][0]] == i]
                    if station_data.empty:
                        pass
                    else:
                        if self.data == 3:
                            date_gai = date_1(station_data)
                            station_data_1 = station_data.copy()
                            station_data_1['handel_data'] = date_gai
                        else:
                            station_data_1 = station_data.copy()
                            station_data_1['handel_data'] = station_data[self.label[0][1]].astype(int)
                        station_data_1.sort_values(by=['handel_data'], ascending=True, inplace=True)
                        station_data_1.reset_index(drop=True)
                        station_list = list(station_data_1['handel_data'].values)
                        station_rain = list(station_data_1[self.label[0][-1]].values)
                        sum_1 = -1
                        for k in station_rain:
                            sum_1 += 1
                            if k == 32700:
                                station_rain[sum_1] = 0
                            else:
                                pass
                        station_hai_sum.append(i)
                        station_rain_sum.append(station_rain)
                        station_data_sum.append(station_list)
                self.bai.emit(15)
                slope_sum = []
                slope_rain = []
                jin = 1
                du = len(list(date_slope_point[self.label[2][1]].values))
                for i_1, x_1, y_1 in zip(date_slope_point[self.label[2][0]],
                                         date_slope_point[self.label[2][1]],
                                         date_slope_point[self.label[2][2]]):
                    sum = 0
                    jin += 1
                    self.bai.emit(15 + jin / du * 60)
                    for i_2, n, x_2, y_2 in zip(date_station[self.label[1][0]],
                                                date_station[self.label[1][1]],
                                                date_station[self.label[1][2]],
                                                date_station[self.label[1][3]], ):
                        if i_2 in station_hai_sum:
                            index_hai = station_hai_sum.index(i_2)
                            if i_1 in station_data_sum[index_hai]:
                                sum+=1
                                index_station = station_data_sum[index_hai].index(i_1)
                                slope_rain.append([i_1, y_1, x_1, i_2, n, y_2, x_2] + station_rain_sum[index_hai][index_station - day + 1:index_station + 1][::-1])
                            else:
                                pass
                        else:
                            pass
                    slope_sum.append(sum)
                while 0 in slope_sum:
                    slope_sum.remove(0)
                return slope_rain, slope_sum

            def date_1(ls):
                date_str = []
                for i, j, k in zip(list(ls[self.label[0][1]]), list(ls[self.label[0][2]]), list(ls[self.label[0][3]])):
                    if len(str(j)) == 1:
                        j = '0' + str(j)
                    else:
                        j = str(j)
                    if len(str(k)) == 1:
                        k = '0' + str(k)
                    else:
                        k = str(k)
                    date_str.append(int(str(i) + j + k))
                return date_str

            day = self.can[0]
            danwei = self.can[2]
            min_danwei = self.can[1]
            slope_rain, slope_sum = data_select(date_station, date_station_date, date_slope_point, day)
            slope_rain = pd.DataFrame(slope_rain)
            if slope_rain.empty:
                self.error.emit('搜索到了降雨型滑坡，但似乎你的站点数据在数据库中找不到，请检查你的站点数据或降雨数据库')
            dict = {
                0: '滑坡发生日期', 1: 'Y', 2: 'X', 3: '站点编号', 4: '站点名称', 5: '站点Y坐标', 6: '站点X坐标',
            }
            for i in range(day):
                dict[i + 7] = '前' + str(i) + '天降雨'
            slope_rain.rename(dict, inplace=True, axis='columns')
            if self.save == 'True':
                slope_rain.to_excel(self.path + '\站点与降雨型滑坡统计结果.xlsx', index=False)

            self.success.emit('在给定的降雨数据库中搜寻有效的降雨站点，在降雨站点下，共找到可以对应到降雨站点日期的降雨型滑坡' + str(len(slope_sum)) + '个')
            self.bai.emit(80)
            rain = []  # 插值结果临时储存位置
            arr1 = np.arange(1, day + 1).reshape(1, day)
            df = pd.DataFrame(arr1)  # 创建1行10列dataframe储存插值结果
            x_test_list = []
            y_test_list = []
            k_data = []
            k_Y = []
            k_X = []
            sum = 0
            for i, l in enumerate(slope_sum):
                x_train = list(slope_rain.iloc[sum:slope_sum[i] + sum, 6])
                y_train = list(slope_rain.iloc[sum:slope_sum[i] + sum, 5])
                x_test = slope_rain.iloc[sum + slope_sum[i] - 1, 2]
                x_test = np.array(x_test, dtype=float)
                x_test_list.append(x_test)
                y_test = slope_rain.iloc[sum + slope_sum[i] - 1, 1]
                y_test = np.array(y_test, dtype=float)
                y_test_list.append(y_test)
                k_X.append(x_test)
                k_Y.append(y_test)
                k_data.append(slope_rain.iloc[sum + slope_sum[i] - 1, 0])
                for i_1 in range(day):  # 10天降雨
                    z_train = list(slope_rain.iloc[sum:slope_sum[i] + sum, i_1 + 7])
                    z_train = np.array(z_train)
                    z_train = z_train * danwei
                    if int(np.max(z_train)) == 0:  # 判断z_train是否全为0,OrdinaryKriging()传入z好像不能全为0或全为同一个数?
                        z_train = list(z_train)
                        z_train[0] = 0.01
                    else:
                        z_train = list(z_train)
                    OK = OrdinaryKriging(
                        x_train,  # 已知数据点x
                        y_train,  # 已知数据点y
                        z_train,  # 已知数据点z,传入z_train好像不能全为0
                        variogram_model=self.highcan[2],  # 参数可调"gaussian"
                    )
                    z_test, ss = OK.execute("points", x_test_list,
                                            y_test_list)
                    rain.append(float(
                        z_test))  # OK.execute('points',x,y)中x,y以列表形式传入,插值z_test类型<class 'numpy.ma.core.MaskedArray'>，返回为列表
                sum = sum + slope_sum[i]
                df.loc[len(df.index)] = rain  # 将插值结果储存到dataframe
                rain.clear()
                x_test_list.clear()
                y_test_list.clear()
            df.drop([0], axis=0, inplace=True)  # 删除创建的dataframe中第一行值(不需要)
            df[df < 0] = 0

            df.insert(loc=0, column='X', value=k_X)  # 插入滑坡点x坐标
            df.insert(loc=0, column='Y', value=k_Y)  # 插入滑坡点y坐标
            df.insert(loc=0, column='滑坡发生日期', value=k_data)  # 插入滑坡点日期
            dict = {}
            for i in range(day):
                dict[i] = '前' + str(i) + '天降雨'
            df.rename(dict, inplace=True, axis='columns')
            if self.save == 'True':
                df.to_excel(self.path + '\克里金插值结果.xlsx', index=False)
            self.bai.emit(90)
            data_array = np.array(df, dtype=int)
            data_slope = pd.DataFrame(data_array)
            data_array = data_array.tolist()
            num = -1
            for i_1 in data_array:
                num += 1
                sum = 0
                for i_2 in range(len(i_1) - 3):
                    if i_1[i_2 + 3] >= min_danwei/0.8**i_2:
                        sum += 1
                    else:
                        try:
                            if i_1[i_2+4] >= min_danwei *(i_2+1):
                                sum+=1
                            else:
                                break
                        except:
                            break
                data_array[num].append(sum)
            data_slope = pd.DataFrame(data_array)
            insert = data_slope.shape[1]
            data_slope.drop(data_slope.index[(data_slope[insert - 1] == 0)], inplace=True)
            data_slope.drop(data_slope.index[(data_slope[3] == 0)], inplace=True)
            data_slope.drop(data_slope.index[(data_slope[insert-1] < self.highcan[0])],inplace=True)#  ?
            data_slope.sort_values(by=insert - 1, ascending=True, inplace=True)
            data_slope = data_slope.reset_index(drop=True)
            # print(data_slope)#降雨历时统计完成,进行累计降雨量计算

            if data_slope.empty:
                self.error.emit('在去除某些降雨型滑坡降雨历时小于'+str(self.highcan[0])+'天的数据后，已经没有降雨型滑坡了')
            data_array = np.array(data_slope)
            data_array = data_array.tolist()
            num_2 = -1
            for i_1 in data_array:
                num_2 += 1
                Cumulative = 0
                for i_2 in range(i_1[insert - 1]):
                    Cumulative = i_1[3 + i_2] * 0.8 ** i_2 + Cumulative
                data_array[num_2].append(round(Cumulative))
            data_slope = pd.DataFrame(data_array)


            # print(data_slope)#得到累计降雨量,拟合
            data_slope.drop(data_slope.index[(data_slope[insert] <= self.highcan[1])],inplace=True)
            data_slope.drop(data_slope.index[(data_slope[insert] >= 300)], inplace=True)
            if data_slope.empty:
                self.error.emit('在去除某些降雨型滑坡前期有效降雨量小于'+str(self.highcan[1])+'mm的数据后，已经没有降雨型滑坡了')
            data_slope=data_slope.reset_index(drop=True)
            def function(x, a, b):
                return np.log(a) + b * x

            x = list(data_slope[insert - 1].values)
            y = list(data_slope[insert].values)
            if len(x) == 1:
                x = x * 3
                y = y * 3
            a, b = curve_fit(function, np.log(np.array(x)), np.log(np.array(y)))[0]
            self.success.emit('传统降雨阈值曲线: y=a*x^b')
            self.success.emit('a=' + str(a))
            self.success.emit('b=' + str(b))

            data_array = np.array(data_slope)
            num_3 = -1
            compare = []
            insert = data_slope.shape[1]
            for i, j in zip(data_array[:, insert - 2], data_array[:, insert - 1]):
                num_3 += 1
                a_b = j / i ** b
                compare.append(a_b)
            compare_1 = np.array(compare).reshape(-1, 1)
            data_array = np.append(data_array, compare_1, axis=1)
            data_slope = pd.DataFrame(data_array)
            insert = data_slope.shape[1]
            data_slope.sort_values(by=insert - 1, ascending=True, inplace=True)
            data_slope = data_slope.reset_index(drop=True)

            # print(data_slope)
            num_4 = len(data_slope[insert - 1].values)
            for i in range(1, 20):
                self.success.emit(
                    'p=' + str(i * 5) + '%' + ': a=' + str(data_slope.iloc[int(num_4 * 0.01 * i * 5), insert - 1]))

            num_6 = len(data_slope[insert - 1].values)
            insert_h = data_slope.shape[0]
            P = np.linspace(0.05, 1, 20)
            sca = []
            D = []
            gai = []
            for i in P:
                if int(num_6 * i) == insert_h:
                    a = data_slope.iloc[insert_h - 1, insert - 1]
                else:
                    a = data_slope.iloc[int(num_6 * i), insert - 1]
                for i_2 in range(1, 11):
                    sca.append(a * i_2 ** b)
                    D.append(i_2)
                    gai.append(i)
            sca_ = np.array(sca).reshape(-1, 1)

            D_ = np.array(D).reshape(-1, 1)
            gai_ = np.array(gai).reshape(-1, 1)
            zon = np.append(D_, sca_, axis=1)
            zon = np.append(zon, gai_, axis=1)
            zon = pd.DataFrame(zon)

            def function_1(x, a_1, b_1, c_1):
                return 1 / (1 + np.exp(a_1 + b_1 * np.array(x[0]) + c_1 * np.array(x[1])))

            z_1 = np.array(zon[2])

            a_1, b_1, c_1 = curve_fit(function_1, zon, z_1, bounds=(-10, [10, 10, 10]))[0]
            # ni=goodness_of_fit(zon.iloc[:,:2],z_1)
            self.success.emit('降雨型滑坡连续概率值的逻辑回归方程: 1/P=1+e^(a+b*D+c*EE)')
            self.success.emit('(参考)a=' + str(a_1))
            self.success.emit('(参考)b=' + str(b_1))
            self.success.emit('(参考)c=' + str(c_1))
            zon.columns = ['X:降雨历时', 'Y:前期有效降雨量', 'Z:概率']
            dict = {
                0: '滑坡发生日期', 1: 'Y', 2: 'X', insert - 1: 'a值', insert - 2: '前期有效降雨量',
                insert - 3: '降雨历时'
            }
            for i in range(day):
                dict[i + 3] = '前' + str(i) + '天降雨'
            data_slope.rename(dict, inplace=True, axis='columns')
            if self.save == 'True':
                zon.to_excel(self.path + '\连续概率降雨非线性方程拟合数据.xlsx', index=False, header=True)
                data_slope.to_excel(self.path + '\统计结果.xlsx', index=False)
            self.bai.emit(100)
            self.success.emit('完成')
        except Exception as e:
            self.error.emit('错误！\n'
                            '你数据对应的列名似乎没有选对或者选择了错误的数据\n'+str(e))
# 下拉复选框实现
class CheckableComboBox(QtWidgets.QComboBox):
    def __init__(self, parent=None):
        super(CheckableComboBox, self).__init__(parent)
        self.view().pressed.connect(self.handleItemPressed)
        self.setModel(QtGui.QStandardItemModel(self))

    def handleItemPressed(self, index):
        item = self.model().itemFromIndex(index)
        if item.checkState() == QtCore.Qt.Checked:
            item.setCheckState(QtCore.Qt.Unchecked)
        else:
            item.setCheckState(QtCore.Qt.Checked)
    def getCheckItem(self):
        #getCheckItem可以获得选择的项目text
        checkedItems = []
        for index in range(self.count()):
            item = self.model().item(index)
            if item.checkState() == QtCore.Qt.Checked:
                checkedItems.append(item.text())
        return checkedItems
    def checkedItems(self):
        checkedItems = []
        for index in range(self.count()):
            item = self.model().item(index)
            if item.checkState() == QtCore.Qt.Checked:
                checkedItems.append(item)
        return checkedItems

# @colorful('blueDeep')
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        # 函数内控件(对象)调用
        # self.txt_s=None

        #设置窗体标题和尺寸
        self.setWindowTitle('我的系统')

        self.resize(1500,900)

        #窗体位置
        qr=self.frameGeometry()
        cp=QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)

        #设置图标
        icon = QIcon()
        icon.addPixmap(QPixmap(r'1.jpg'))
        self.setWindowIcon(icon)

        layout=QVBoxLayout()
        layout_H=QHBoxLayout()
        layout_2H=QVBoxLayout()
        layout_2H.addLayout(self.header2())
        layout_2H.addLayout(self.header4())
        # layout_2H.addStretch()
        layout_H.addLayout(self.header1())
        layout_H.addLayout(self.header3())
        layout.addLayout(layout_H)
        layout.addLayout(layout_2H)
        frame=QWidget()
        frame.setLayout(layout)
        menu=self.menuBar()
        seting=menu.addMenu('高级设置')
        preview=menu.addMenu('预览')
        help=menu.addMenu('帮助')
        preview_1=preview.addAction('打开预览')
        preview_1.triggered.connect(self.preview_1)
        preview_2=preview.addAction('关闭预览')
        preview_2.triggered.connect(self.preview_2)
        help_1=help.addAction('帮助')
        help_1.triggered.connect(self.help)
        seting_1=seting.addAction('高级设置')
        self.highcan = [0, 0, 'gaussian']
        seting_1.triggered.connect(self.seting)
        self.setCentralWidget(frame)

        # window_pale = QtGui.QPalette()
        # window_pale.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QPixmap("G:/360downloads/239680.jpg")))
        # self.setPalette(window_pale)
        #
        # self.setWindowOpacity(0.7)  # 设置窗口透明度
        # self.setAttribute(QtCore.Qt.WA_TranslucentBackground)


        self.show()
    def header1(self):
        headerH=QHBoxLayout()
        headerHL=QHBoxLayout()
        header=QVBoxLayout()
        header1=QVBoxLayout()
        header2=QVBoxLayout()
        header3=QVBoxLayout()
        header1_1=QHBoxLayout()
        header1_2=QHBoxLayout()
        header2_1 = QHBoxLayout()
        header2_2 = QHBoxLayout()
        header3_1 = QHBoxLayout()
        header3_2 = QHBoxLayout()


        lable1=QLabel('降雨站点数据库：')
        lable1.setFixedSize(120,50)
        lable2=QLabel('滑坡区降雨站点：')
        lable2.setFixedSize(120,50)
        # lable2.resize(500,500)
        # print(lable2.height())
        lable3=QLabel('滑坡数据：')
        # lable3.setMinimumSize(0,0)
        # lable3.setMaximumSize(QSize(1000, 1000))
        # lable3.resize(50,50)
        lable3.setFixedSize(120,50)
        self.edit1=QLineEdit()
        self.edit1.setPlaceholderText('输入文件路径')
        self.edit2 = QLineEdit()
        self.edit2.setPlaceholderText('输入文件路径')
        self.edit3 = QLineEdit()
        self.edit3.setPlaceholderText('输入文件路径')
        btn1=QPushButton(QIcon(r'2.jpg'),'',self)
        self.btn1_start = thrings()
        btn1.clicked.connect(self.btn1_c)
        self.btn1_start.success.connect(self.success_)
        self.btn1_start.error.connect(self.error_)
        btn2=QPushButton(QIcon(r'2.jpg'),'',self)
        self.btn2_start=thrings()
        btn2.clicked.connect(self.btn2_c)
        self.btn2_start.success.connect(self.success_2)
        self.btn2_start.error.connect(self.error_2)
        btn3=QPushButton(QIcon(r'2.jpg'),'',self)
        self.btn3_start=thrings()
        btn3.clicked.connect(self.btn3_c)
        self.btn3_start.success.connect(self.success_3)
        self.btn3_start.error.connect(self.error_3)

        cb1_lable=QLabel('站点编号')
        self.cb1=QComboBox()
        cb2_lable = QLabel('日期')
        self.cb2=CheckableComboBox()
        cb3_lable = QLabel('降雨数据')
        self.cb3=QComboBox()
        cb1_z_lable = QLabel('站点编号')
        self.cb1_z = QComboBox()
        cb2_z_lable = QLabel('站点名称')
        self.cb2_z = QComboBox()
        cb3_z_lable = QLabel('站点X坐标')
        self.cb3_z = QComboBox()
        cb4_z_lable = QLabel('站点Y坐标')
        self.cb4_z=QComboBox()
        cb1_h_lable = QLabel('滑坡发生时间')
        self.cb1_h = QComboBox()
        cb2_h_lable = QLabel('滑坡X坐标')
        self.cb2_h = QComboBox()
        cb3_h_lable = QLabel('滑坡Y坐标')
        self.cb3_h = QComboBox()
        cb4_h_lable = QLabel('滑坡诱发因素')
        self.cb4_h = QComboBox()
        header1_1.addWidget(lable1)
        header1_1.addWidget(self.edit1)
        header1_1.addWidget(btn1)
        header2_1.addWidget(lable2)
        header2_1.addWidget(self.edit2)
        header2_1.addWidget(btn2)
        header3_1.addWidget(lable3)
        header3_1.addWidget(self.edit3)
        header3_1.addWidget(btn3)
        header1_2.addStretch()
        header1_2.addWidget(cb1_lable)
        header1_2.addWidget(self.cb1)
        header1_2.addWidget(cb2_lable)
        header1_2.addWidget(self.cb2)
        header1_2.addWidget(cb3_lable)
        header1_2.addWidget(self.cb3)
        header2_2.addStretch()
        header2_2.addWidget(cb1_z_lable)
        header2_2.addWidget(self.cb1_z)
        header2_2.addWidget(cb2_z_lable)
        header2_2.addWidget(self.cb2_z)
        header2_2.addWidget(cb3_z_lable)
        header2_2.addWidget(self.cb3_z)
        header2_2.addWidget(cb4_z_lable)
        header2_2.addWidget(self.cb4_z)
        header3_2.addStretch()
        header3_2.addWidget(cb1_h_lable)
        header3_2.addWidget(self.cb1_h)
        header3_2.addWidget(cb2_h_lable)
        header3_2.addWidget(self.cb2_h)
        header3_2.addWidget(cb3_h_lable)
        header3_2.addWidget(self.cb3_h)
        header3_2.addWidget(cb4_h_lable)
        header3_2.addWidget(self.cb4_h)
        lable4=QLabel('读取较大的xlsx或xls文件较慢，推荐使用txt格式(‘utf-8’)编码')
        self.label9=QLabel('未读取')
        header1_insert=QHBoxLayout()
        header1_insert.addWidget(lable4)
        header1_insert.addStretch()
        header1_insert.addWidget(self.label9)
        header1.addLayout(header1_insert)
        header1.addLayout(header1_1)
        header1.addLayout(header1_2)
        header2.addLayout(header2_1)
        header2.addLayout(header2_2)
        header3.addLayout(header3_1)
        header3.addLayout(header3_2)
        header.addLayout(header1)
        header.addLayout(header2)
        header.addLayout(header3)
        header.addStretch()
        header_2insert=QHBoxLayout()
        lable5=QLabel('降雨天数:')
        lable5.setToolTip('默认为10天')
        self.edit4=QLineEdit()
        self.edit4.setPlaceholderText('10')
        self.edit4.setFixedSize(100,25)
        self.edit4.setToolTip('默认为10天')
        lable6=QLabel('降雨历时统计最小降雨量(mm):')
        lable6.setToolTip('默认为5mm')
        self.edit5=QLineEdit()
        self.edit5.setPlaceholderText('5')
        self.edit5.setFixedSize(100,25)
        self.edit5.setToolTip('默认为5mm')
        lable7=QLabel('数据库降雨量单位')
        lable7.setToolTip('默认单位为mm，如果单位是cm，输入10即可，如果单位是m，输入100即可，如果单位为0.1mm，输入0.1即可')
        self.edit6=QLineEdit()
        self.edit6.setPlaceholderText('mm')
        self.edit6.setToolTip('默认单位为mm，如果单位是cm，输入0.1即可，如果单位是m，输入0.01即可，如果单位为0.1mm，输入10即可')
        self.edit6.setFixedSize(100,25)
        self.radio=QRadioButton()
        self.radio.setText('是否保存中间数据')
        self.radio.setToolTip('保存如一个站点下降雨型滑坡的数据、降雨型滑坡插值数据、统计降雨历时前期有效降雨量a值得数据等')
        self.radio.toggled.connect(self.radio_c)
        self.btn6=QPushButton('选择数据保存位置')
        # self.btn6.setEnabled(False)
        self.btn6.hide()
        self.btn6.clicked.connect(self.btn6_c)
        header_2insert.addStretch()
        header_2insert.addWidget(lable5)
        header_2insert.addWidget(self.edit4)
        header_2insert.addWidget(lable6)
        header_2insert.addWidget(self.edit5)
        header_2insert.addWidget(lable7)
        header_2insert.addWidget(self.edit6)
        # header_2insert.addWidget(radio)
        self.header_3insert=QHBoxLayout()
        self.header_3insert.addStretch()
        self.header_3insert.addWidget(self.radio)
        self.header_3insert.addWidget(self.btn6)
        header.addLayout(self.header_3insert)
        header.addLayout(header_2insert)
        header_insert=QHBoxLayout()
        self.btn4=QPushButton('开始')
        self.suan=Suan()
        self.btn4.clicked.connect(self.btn4_c)
        self.suan.success.connect(self.success_4)
        self.suan.error.connect(self.error_4)
        self.suan.bai.connect(self.jindu)
        btn5=QPushButton('刷新')
        btn5.setToolTip('请输入3个路径后再刷新')
        btn5.clicked.connect(self.btn5_c)
        lable9=QLabel('手动输入路径请点击刷新:')
        self.lable8=QLabel('未开始')
        header_insert.addWidget(self.lable8)
        header_insert.addStretch()
        header_insert.addWidget(lable9)
        header_insert.addWidget(btn5)
        header_insert.addWidget(self.btn4)
        header.addLayout(header_insert)
        # header.addStretch()
        headerH.addLayout(header)
        frame = QFrame()
        frame.setFrameShape(QFrame.VLine)
        frame.setFrameShadow(QFrame.Raised)
        headerHL.addWidget(frame)
        headerH.addLayout(headerHL)
        return headerH
    def header2(self):
        header=QVBoxLayout()
        self.table=QTableWidget(0,40)
        self.table.hide()
        self.label_pre=QLabel('预览')
        self.label_pre.hide()
        frame = QFrame()
        frame.setFrameShape(QFrame.HLine)
        frame.setFrameShadow(QFrame.Raised)
        # frame.setLineWidth(100)
        header.addWidget(frame)
        header.addWidget(self.label_pre)
        QTableWidget.setStyleSheet(self.table, "QHeaderView::section{background:white;color: black;}")
        header.addWidget(self.table)
        return header
    def header4(self):
        header=QVBoxLayout()
        label=QLabel('日志:')
        label1=QLabel('进度:')
        spliter=QSplitter(Qt.Horizontal)
        self.text_browser2=QTextBrowser()
        self.progress_bar = QProgressBar()
        self.progress_bar.setRange(0, 100)
        self.progress_bar.setValue(0)
        header.addWidget(label)
        header.addWidget(self.text_browser2)
        spliter.addWidget(label1)
        spliter.addWidget(self.progress_bar)
        spliter.setStretchFactor(0,1)
        spliter.setStretchFactor(1,9)
        header.addWidget(spliter)
        return header
    def header3(self):
        header=QVBoxLayout()
        # frame=QFrame()
        # frame.setFrameShape(QFrame.HLine)
        # frame.setFrameShadow(QFrame.Raised)
        # frame.setLineWidth(100)
        # header.addWidget(frame)
        # header.addWidget(spliter)
        lable=QLabel('结果：')
        self.text_browser=QTextBrowser()
        header.addWidget(lable)
        # text_li=QTextBrowser()
        header.addWidget(self.text_browser)
        return header
    def btn1_c(self):
        file_name=QFileDialog.getOpenFileName(self,'open file','C:\\','files (*.xls *.xlsx *.txt *.csv)')
        self.edit1.setText(file_name[0])
        # from thring import thrings
        if file_name[0] != '':
            if file_name[0].split('.')[1] == 'txt' or 'csv':
                self.btn1_start.c(file_name[0])
                self.label9.setText('读取中')
                self.btn1_start.start()
                # thread=thrings(file_name[0])
                # thread.success.connect(self.success_)
                # thread.error.connect(self.error_)
                # thread.start()
                # self.sql1=pd.read_csv(file_name[0])
                # self.cb1.addItems(self.sql.columns.values)
                # for index,element in enumerate(self.sql.columns.values):
                #     self.cb2.addItem(element)
                #     item = self.cb2.model().item(index, 0)
                #     item.setCheckState(QtCore.Qt.Unchecked)
                # self.cb3.addItems(self.sql.columns.values)
            if file_name[0].split('.')[1] == 'xls' or 'xlsx':
                self.btn1_start.c(file_name[0])
                self.label9.setText('读取中')
                self.btn1_start.start()
                # thread = thrings(file_name[0])
                # thread.success.connect(self.success_)
                # thread.error.connect(self.error_)
                # thread.start()
                # self.sql1=pd.read_excel(file_name[0])
                # self.cb1.addItems(self.sql.columns.values)
                # for index,element in enumerate(self.sql.columns.values):
                #     self.cb2.addItem(element)
                #     item = self.cb2.model().item(index, 0)
                #     item.setCheckState(QtCore.Qt.Unchecked)
                #self.cb2.getCheckItem() #获取所获得的项目
                # self.cb3.addItems(self.sql.columns.values)
        else:
            pass
    def btn2_c(self):
        file_name = QFileDialog.getOpenFileName(self, 'open file', 'C:\\', 'files (*.xls *.xlsx *.txt *.csv)')
        self.edit2.setText(file_name[0])
        if file_name[0] != '':
            if file_name[0].split('.')[1] == 'txt' or 'csv':
                self.btn2_start.c(file_name[0])
                self.btn2_start.start()
                # self.sql2 = pd.read_csv(file_name[0])
                # self.cb1_z.addItems(self.sql.columns.values)
                # self.cb2_z.addItems(self.sql.columns.values)
                # self.cb3_z.addItems(self.sql.columns.values)
                # self.cb4_z.addItems(self.sql.columns.values)
            if file_name[0].split('.')[1] == 'xls' or 'xlsx':
                self.btn2_start.c(file_name[0])
                self.btn2_start.start()
                # self.sql2 = pd.read_excel(file_name[0])
                # self.cb1_z.addItems(self.sql.columns.values)
                # self.cb2_z.addItems(self.sql.columns.values)
                # self.cb3_z.addItems(self.sql.columns.values)
                # self.cb4_z.addItems(self.sql.columns.values)
        else:
            pass
    def success_2(self,list):
        self.z=list[0]
        self.cb1_z.clear()
        self.cb1_z.addItems(list[0].columns.values)
        self.cb2_z.clear()
        self.cb2_z.addItems(list[0].columns.values)
        self.cb3_z.clear()
        self.cb3_z.addItems(list[0].columns.values)
        self.cb4_z.clear()
        self.cb4_z.addItems(list[0].columns.values)
        self.table.setRowCount(0)
        self.table.clearContents()
        for id, ite in enumerate(list[0].columns.values):
            item = QTableWidgetItem()
            item.setText(str(ite))
            self.table.setHorizontalHeaderItem(id, item)
            self.table.setColumnWidth(id, 200)
        current_row_count = self.table.rowCount()  # 获取当前表格有多少行
        if 10 >= list[0].shape[0]:
            a = list[0].shape[0]
        else:
            a = 10
        for id in range(a):
            self.table.insertRow(current_row_count)
            for i in range(len(list[0].columns.values)):
                cell = QTableWidgetItem(str(list[0].iloc[id, i]))
                # cell.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)  # 单元格设置为不可修改
                self.table.setItem(current_row_count, i, cell)
            current_row_count += 1
    def error_2(self):
        QMessageBox.warning(self, '错误', '滑坡区降雨站点数据错误')
    def btn3_c(self):
        file_name = QFileDialog.getOpenFileName(self, 'open file', 'C:\\', 'files (*.xls *.xlsx *.txt *.csv)')
        self.edit3.setText(file_name[0])
        if file_name[0] != '':
            if file_name[0].split('.')[1] == 'txt' or 'csv':
                self.btn3_start.c(file_name[0])
                self.btn3_start.start()
                # self.sql3 = pd.read_csv(file_name[0])
                # self.cb1_h.addItems(self.sql.columns.values)
                # self.cb2_h.addItems(self.sql.columns.values)
                # self.cb3_h.addItems(self.sql.columns.values)
                # self.cb4_h.addItems(self.sql.columns.values)
            if file_name[0].split('.')[1] == 'xls' or 'xlsx':
                self.btn3_start.c(file_name[0])
                self.btn3_start.start()
                # self.sql3 = pd.read_excel(file_name[0])
                # self.cb1_h.addItems(self.sql.columns.values)
                # self.cb2_h.addItems(self.sql.columns.values)
                # self.cb3_h.addItems(self.sql.columns.values)
                # self.cb4_h.addItems(self.sql.columns.values)
        else:
            pass

    def success_3(self, list):
        self.h=list[0]
        self.cb1_h.clear()
        self.cb1_h.addItems(list[0].columns.values)
        self.cb2_h.clear()
        self.cb2_h.addItems(list[0].columns.values)
        self.cb3_h.clear()
        self.cb3_h.addItems(list[0].columns.values)
        self.cb4_h.clear()
        self.cb4_h.addItems(list[0].columns.values)
        self.table.setRowCount(0)
        self.table.clearContents()
        for id, ite in enumerate(list[0].columns.values):
            item = QTableWidgetItem()
            item.setText(str(ite))
            self.table.setHorizontalHeaderItem(id, item)
            self.table.setColumnWidth(id, 200)
        current_row_count = self.table.rowCount()  # 获取当前表格有多少行
        if 10 >= list[0].shape[0]:
            a = list[0].shape[0]
        else:
            a = 10
        for id in range(a):
            self.table.insertRow(current_row_count)
            for i in range(len(list[0].columns.values)):
                cell = QTableWidgetItem(str(list[0].iloc[id, i]))
                # cell.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)  # 单元格设置为不可修改
                self.table.setItem(current_row_count, i, cell)
            current_row_count += 1
    def error_3(self):
        QMessageBox.warning(self, '错误', '滑坡数据错误')
    def success_(self,list):
        self.cb1.clear()
        self.cb1.addItems(list[0].columns.values)
        self.label9.setText('读取完成')
        self.s=list[0]
        self.cb2.clear()
        for index, element in enumerate(list[0].columns.values):
            self.cb2.addItem(element)
            item = self.cb2.model().item(index, 0)
            item.setCheckState(QtCore.Qt.Unchecked)
        self.cb3.clear()
        self.cb3.addItems(list[0].columns.values)
        for id, ite in enumerate(list[0].columns.values):
            item = QTableWidgetItem()
            item.setText(str(ite))
            self.table.setHorizontalHeaderItem(id, item)
            self.table.setColumnWidth(id, 200)
        current_row_count = self.table.rowCount()  # 获取当前表格有多少行
        if 10 >= list[0].shape[0]:
            a=list[0].shape[0]
        else:
            a=10
        for id in range(a):
            self.table.insertRow(current_row_count)
            for i in range(len(list[0].columns.values)):
                cell = QTableWidgetItem(str(list[0].iloc[id,i]))
                # cell.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)  # 单元格设置为不可修改
                self.table.setItem(current_row_count, i, cell)
            current_row_count += 1
    def error_(self):
        self.label9.setText('读取失败')
        QMessageBox.warning(self, '错误', '降雨站点数据库数据错误')
    def radio_c(self):
        if self.radio.isChecked():
            # self.header_3insert.addWidget(self.btn6)
            # self.btn6.setEnabled(True)
            self.btn6.show()
            # self.btn6.isVisible(True)
        else:
            # self.btn6.setEnabled(False)
            # self.btn6.isVisible(False)
            self.btn6.hide()
            # self.header_3insert.itemAt(2).widget().deleteLater()
            # PyQt5.sip.delete(self.btn6)
    def btn6_c(self):
        self.directory1 = QFileDialog.getExistingDirectory(self,"选取文件夹","C:\\")
    def btn4_c(self):
        sql=[self.cb1.itemText(self.cb1.currentIndex()),self.cb2.getCheckItem(),
             self.cb3.itemText(self.cb3.currentIndex())
             ]
        z_sql=[self.cb1_z.itemText(self.cb1_z.currentIndex()),self.cb2_z.itemText(self.cb2_z.currentIndex()),
               self.cb3_z.itemText(self.cb3_z.currentIndex()),self.cb4_z.itemText(self.cb4_z.currentIndex())
               ]
        h_sql = [self.cb1_h.itemText(self.cb1_h.currentIndex()), self.cb2_h.itemText(self.cb2_h.currentIndex()),
                 self.cb3_h.itemText(self.cb3_h.currentIndex()), self.cb4_h.itemText(self.cb4_h.currentIndex())
                 ]
        if len(self.cb2.getCheckItem()) == 3:
            data=3
        elif len(self.cb2.getCheckItem()) == 1:
            data=1
        else:
            QMessageBox.warning(self, '错误', '降雨站点数据库日期标签选择错误')
            return
        c=sql[1]
        del sql[1]
        for i in c[::-1]:
            sql.insert(1,i)
        for i in sql:
            if i == '':
                QMessageBox.warning(self, '错误', '降雨站点数据库未导入')
                return
            else:
                pass
        for i in z_sql:
            if i == '':
                QMessageBox.warning(self, '错误', '滑坡区降雨站点未导入')
                return
            else:
                pass
        for i in h_sql:
            if i == '':
                QMessageBox.warning(self, '错误', '滑坡数据未导入')
                return
            else:
                pass
        can=[10,5,1]
        if self.edit4.text() != '':
            can[0]=int(self.edit4.text())
        if self.edit5.text() != '':
            can[1]=int(self.edit5.text())
        if self.edit6.text() != '':
            can[2]=float(self.edit6.text())
        try:
            if self.radio.isChecked() == True and self.directory1 != '':
                save = 'True'
            else:
                save = 'False'
                self.directory1='1'
        except:
            save='False'
            self.directory1='1'
        self.suan.c([sql,z_sql,h_sql],can,save,self.s,self.z,self.h,data,self.directory1,self.highcan)
        self.lable8.setText('运行中')
        self.suan.start()
        self.btn4.setEnabled(False)
    def success_4(self,zifu):
        self.text_browser.append(zifu)
        if zifu == '完成':
            self.lable8.setText('完成')
            self.btn4.setEnabled(True)
    def error_4(self,rizhi):
        self.text_browser2.append(rizhi)
        self.btn4.setEnabled(True)
    def btn5_c(self):
        if self.edit1.text() == '':
            QMessageBox.warning(self, '错误', '请输入降雨数据库路径')
            return
        elif self.edit1.text() != '':
            self.btn1_start.c(self.edit1.text())
            self.label9.setText('读取中')
            self.btn1_start.start()
        else:
            pass
        if self.edit2.text() == '':
            QMessageBox.warning(self, '错误', '请输入降雨站点路径')
            return
        elif self.edit2.text() != '':
            self.btn2_start.c(self.edit2.text())
            self.btn2_start.start()
        else:
            pass
        if self.edit3.text() == '':
            QMessageBox.warning(self, '错误', '请输入滑坡数据路径')
        elif self.edit3.text() != '':
            self.btn3_start.c(self.edit3.text())
            self.btn3_start.start()
        else:
            pass

    def preview_1(self):
        self.table.show()
        self.label_pre.show()
    def preview_2(self):
        self.table.hide()
        self.label_pre.hide()
    def help(self):
        self.help=help()
        self.help.show()
    def jindu(self,a):
        self.progress_bar.setValue(a)
    def seting(self):
        self.jiemian2=gseting()
        self.jiemian2.show()
        self.jiemian2.canshu.connect(self.highseting)
    def highseting(self,list):

        self.highcan=list


class gseting(QWidget):
    canshu=pyqtSignal(list)
    def __init__(self):
        super().__init__()
        self.setWindowTitle('高级设置')
        self.resize(800, 600)
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        icon = QIcon()
        icon.addPixmap(QPixmap(r'4.jpg'))
        self.setWindowIcon(icon)
        layout=QVBoxLayout()
        layout1=QHBoxLayout()
        label=QLabel('克里金插值拟合模型:')
        self.cb1 = QComboBox()
        self.cb1.addItems(['gaussian','linear','power','spherical','exponential','hole-effect'])
        layout1.addStretch()
        layout1.addWidget(label)
        layout1.addWidget(self.cb1)
        layout1.addStretch()
        labelz=QLabel('降雨型滑坡降雨历时与前期有效降雨量筛选条件:')
        layout2=QHBoxLayout()
        layout2.addWidget(labelz)
        layout2.addStretch()
        layout3=QHBoxLayout()
        label1=QLabel('剔除降雨历时小于')
        self.edit1 = QLineEdit()
        label2=QLabel('天的降雨型滑坡')
        self.edit1.setPlaceholderText('0')
        layout3.addStretch()
        layout3.addWidget(label1)
        layout3.addWidget(self.edit1)
        layout3.addWidget(label2)
        layout3.addStretch()
        layout4=QHBoxLayout()
        label3=QLabel('剔除前期有效降雨量小于')
        self.edit2 = QLineEdit()
        label4=QLabel('mm的降雨型滑坡')
        self.edit2.setPlaceholderText('0')
        layout4.addStretch()
        layout4.addWidget(label3)
        layout4.addWidget(self.edit2)
        layout4.addWidget(label4)
        layout4.addStretch()
        layout5=QHBoxLayout()
        btn1=QPushButton('确认')
        btn2=QPushButton('取消')
        btn1.clicked.connect(self.btn1_click)
        btn2.clicked.connect(self.close)
        layout5.addStretch()
        layout5.addWidget(btn2)
        layout5.addWidget(btn1)
        layout.addLayout(layout1)
        layout.addLayout(layout2)
        layout.addLayout(layout3)
        layout.addLayout(layout4)
        layout.addLayout(layout5)
        self.setLayout(layout)
        self.show()
    def btn1_click(self):
        can=[0,0]
        can.append(self.cb1.itemText(self.cb1.currentIndex()))
        if self.edit1.text() != '':
            can[0]=int(self.edit1.text())
        if self.edit2.text() != '':
            can[1]=int(self.edit2.text())
        self.canshu.emit(can)
        self.close()


class help(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('帮助')

        self.resize(800, 600)
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        icon = QIcon()
        icon.addPixmap(QPixmap(r'3.jpg'))
        self.setWindowIcon(icon)
        browser=QTextBrowser()
        browser.append('  导入的数据最好具有表头，方便选择，可以直接从属性表中导出txt格式。\n'
                       '  如果手动输入文件路径，请将三个文件路径都输入后在点击刷新。'
                       '  对于降雨站点数据库：降雨站点数据库较大，打开速度较慢，打开后，根据对应提示，选择下拉框对应列的名称。\n'
                       '  对于滑坡区降雨站点：根据你的研究区范围裁剪一个适合的降雨站点范围，降雨站点范围可以大于你的研究区，\n'
                       '打开较快，打开后，根据对应提示，选择下拉框对应列的名称。\n'
                       '  对于滑坡数据：打开较快，打开后，根据对应提示，选择下拉框对应列的名称。')
        layout=QHBoxLayout()
        layout.addWidget(browser)
        self.setLayout(layout)
        self.show()
if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindow()
    # window = CandyWindow.createWindow(window, 'blue')
    # window.setWindowTitle('我的系统')
    # window_pale = QtGui.QPalette()
    # window_pale.setBrush(window.backgroundRole(), QtGui.QBrush(QtGui.QPixmap("G:/360downloads/239680.jpg")))
    # window.setPalette(window_pale)


    # window.setWindowOpacity(0.7)  # 设置窗口透明度
    window.show()
    sys.exit(app.exec_())